<?php if(!defined('BASEPATH')) exit ('No direct access script allowed');

class Usermodel extends CI_Model
{
	public function get_menu_for_level($user_level)
	{
		$this->db->from('menu');
		$this->db->like('menu_allowed','+'.$user_level.'+');
		$result = $this->db->get();
		return $result;
	}
	public function get_array_menu($id)
	{
		$this->db->select('menu_allowed');
		$this->db->from('menu');
		$this->db->where('menu_id',$id);
		$data = $this->db->get();
		if($data->num_rows() > 0)
		{
			$row = $data->row();
			$level = $row->menu_allowed;
			$arr = explode ('+',$level);
			return $arr;
		}
		else
		{
			die();
		}
	}
	public function get_menu()
	{
		return $this->db->get('menu');
	}
	
	public function get_all_user()
	{
		//$this->db->from('user');
		//$this->db->join('level','level_id=user_level','left');
		return $this->db->get('user');
	}
	public function get_all_level()
	{
		return $this->db->get('level');
	}
	public function tambah_data_user($data)
	{
		$this->db->insert('user',$data);
	}
	public function get_user_by_id($id)
	{
		$this->db->where('ID_USER',$id);
		return $this->db->get('user');
	}
	public function edit_data_user($data,$id)
	{
		$this->db->where('ID_USER',$id);
		$this->db->update('user',$data);
	}
	public function delete_user($id)
	{
		$this->db->where('ID_USER',$id);
		$this->db->delete('user');
	}
}